import Vue from 'vue'
import VueRouter from 'vue-router'
import { getUserDeptList } from '@/api/rectify'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    // component: () => import('@/views/Index')
    component: () => import('@/views/dealtwith/bigscreen')
   
  },
  {
    path: '/wxauth',
    name: 'wxauth',
    component: () => import('@/views/authorize/WxAuth')
  },
  {
    path: '/main/:assessType',
    name: 'main',
    // component: () => import('@/views/MainMenu'),
    component: () => import('@/views/MainMenuCopy'),
    props: true
  },
  {
    path: '/rectify/main/:assessType',
    component: () => import('@/views/rectify/Index'),
    props: true
  },
  {
    path: '/rectify/list/:assessType/:step',
    component: () => import('@/views/rectify/PageRectifyList'),
    props: true
  },
  {
    path: '/grade/:assessType/:operateType',
    name: 'grade',
    component: () => import('@/views/grade/PageGradeList'),
    props: true
  },
  {
    path: '/raise/:assessType/:operateType',
    name: 'raise',
    component: () => import('@/views/raise/PageRaiseList'),
    props: true
  },
  {
    path: '/check/:assessType',
    name: 'check',
    component: () => import('@/views/grade/PageGradeCheck'),
    props: true
  },
  {
    path: '/resume/:assessType/:operateType',
    name: 'resume',
    component: () => import('@/views/grade/PageGradeResume'),
    props: true
  },
  {
    path: '/approve/:assessType',
    name: 'approve',
    component: () => import('@/views/grade/PageGradeApprove'),
    props: true
  },
  {
    path: '/feedback/:assessType',
    name: 'feedback',
    component: () => import('@/views/grade/PageGradeFeedback'),
    props: true
  },
  {
    path: '/raise-approve/:assessType',
    name: 'raise-approve',
    component: () => import('@/views/raise/PageRaiseApprove'),
    props: true
  },
  {
    path: '/analysis/dept-main',
    name: 'analysis-dept-main',
    component: () => import('@/views/analysis/deptIndex'),
    // component: () => import('@/views/analysis/deptIndexCopy'),
    props: true
  },
  {
    path: '/analysis/dept-grade',
    name: 'analysis-dept-grade',
    component: () => import('@/views/analysis/DeptGradeAnalysis'),
    props: true
  },
  {
    path: '/analysis/dept-grade-monitor',
    name: 'analysis-dept-grade-monitor',
    component: () => import('@/views/analysis/DeptGradeMonitor'),
    props: true
  },
  {
    path: '/analysis/dept-rectify-monitor',
    name: 'analysis-dept-rectify-monitor',
    component: () => import('@/views/analysis/DeptRectifyAnalysis/DeptRectifyMonitor'),
    props: true
  },
  {
    path: '/analysis/dept-problem-analysis',
    name: 'dept-problem-analysisr',
    component: () => import('@/views/analysis/deptProblemAnalysis/DeptProblemAnalysis'),
    props: true
  },
  {//单位录入
    path: '/execelIntroduce/introduce',
    name: 'execel-Introduce',
    component: () => import('@/views/execelIntroduce/execelIntroduce'),
    props: true
  },
  {//公司导入
    path: '/execelIntroduce/gsintroduce',
    name: 'execel-gsintroduce',
    component: () => import('@/views/execelIntroduce/execelgsIntroduce'),
    props: true
  },
  {//公司报告
    path: '/Report/ReGsport',
    name: 'Report-gsintroduce',
    component: () => import('@/views/export/DataReport'),
    props: true
  },
  {//待办
    path: '/dealtwith/index',
    name: 'dealt-With',
    component: () => import('@/views/dealtwith/dealtwith'),
    //component: () => import('@/views/dealtwith/dealtwithCopy'),
    props: true,
  },
  {//问题类别查询
    path: '/dealtwith/category',
    name: 'category',
    component: () => import('@/views/dealtwith/category'),
    props: true
  },
  {//数据大屏
    path: '/dealtwith/bigscreen',
    name: 'bigscreen',
    component: () => import('@/views/dealtwith/bigscreen'),
    props: true
  },
  {//考评查询
    path: '/dealtwith/scoreindex/:assessType',
    name: 'scorelist',
    component: () => import('@/views/dealtwith/scoreindex'),
    props: true
  },
  {//公司体系评级
    path: '/dealtwith/companySystemRating',
    name: 'companySystemRating',
    component: () => import('@/views/dealtwith/companySystemRating'),
    props: true
  },
  

  
]

const router = new VueRouter({
  scrollBehavior: () => ({ y: 0 }),
  mode: 'hash', // mode 设置为history ，去掉地址栏上的 # 号
  routes
})

router.beforeEach((to, from, next) => {

  if (process.env.NODE_ENV === 'development') {
    if (!router.app.$options.store.state.authInfo.user) {
      let user = {
        // userid: 'weixing', 
        userid: 'lujiaming',  
        //  userid: 'bingchen', 
        // userid: 'cbef82819e599b12cc879116da6f42ae',
        //  userid: 'zhangjie2',
        // userid: 'longyuming',
        username: '袁鑫',
        roles: {  
          corp: { // 公司对部门
            dept: [
              {
                department_path: '超高压输电公司/公司本部/信息通信运维中心',
                id: 16
              },
              {
                //department_path: '超高压输电公司/广州局/输电管理所/输电所本部',
                department_path: '超高压输电公司/公司本部/基建部',
                //department_path: '超高压输电公司/百色局/基建部',
                
                id: 6231
              }
            ],
            assess_dept: [
              {
                department_path: '超高压输电公司/公司本部/安全监管部（应急指挥中心）',
                id: 5
              }
            ]
          },
          dept: { //单位对部门
            dept: [
              {
                department_path: '超高压输电公司/柳州局/安全监管部',
                id: 6516
              },
              {
                //department_path: '超高压输电公司/广州局/变电管理二所/二所本部',
                department_path: '超高压输电公司/南宁局/生产技术部',
                id: 149
              }
            ],
            assess_dept: [
              {
                department_path: '超高压输电公司/广州局/安全监管部',
                id: 80
              }
            ]
          }
        }
      }
      // console.log(router.app.$options.store.state.authInfo.user.userid)
      getUserDeptList(user.userid).then(res => {
        let { data } = res
        if (data['retCode'] === '0000') {
          user.rectify = data['retData']
          console.log(user)
          router.app.$options.store.commit('authInfo/setUserInfo', user)
        } else {
          console.log(data['retMsg'])
        }
      }, errFunc => {
        // 服务请求通信错误
        console.log(errFunc.toString())
      }).finally(() => next())
    } else {
      next()
    }
  } else {
    // 这里判断Vuex中是否存有微信用户身份信息，如果没有用户详细信息，则通过微信认证接口页面获取；否则进入下一步
    if (router.app.$options.store.state.authInfo.user) {
      console.log('微信已授权')
      next()
    } else {
      console.log('微信未授权')
      // if (!sessionStorage.getItem('targetUrl')) {
      //   sessionStorage.setItem('targetUrl', to.path)
      // }
      if (to.name === 'wxauth') {
        next()
      } else {
        console.log('转授权操作')
        next('/wxauth')
      }
    }
  }

})

export default router



